package logic

import (
	"context"
	"home-info-site/models/mysql"

	"home-info-site/userrpc/internal/svc"
	"home-info-site/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductAddLogic {
	return &ProductAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 创建商品
func (l *ProductAddLogic) ProductAdd(in *userrpc.ProductAddRequest) (*userrpc.ProductAddResponse, error) {
	// todo: add your logic here and delete this line

	product := &mysql.Product{
		UserId:       int32(in.UserId),
		ProductName:  in.ProductName,
		ProductStock: int32(in.ProductStock),
		ProductPrice: in.ProductPrice,
	}
	err := product.ProductAdd(mysql.DB)
	if err != nil {
		return nil, err
	}
	return &userrpc.ProductAddResponse{
		ProductId: int64(product.ID),
	}, nil
}
